﻿using System;
using PicoContainer;
using PicoContainer.Defaults;

namespace XEvolve.Core.Runtime.Internal
{
    internal class XComponentAdapterFactory : IComponentAdapterFactory
    {
        private readonly IExtensionRegistry registry;
        private readonly bool isCaching;

        public XComponentAdapterFactory(IExtensionRegistry registry, bool isCaching)
        {
            this.registry = registry;
            this.isCaching = isCaching;
        }

        public IComponentAdapter CreateComponentAdapter(object componentKey, Type componentImplementation, IParameter[] parameters)
        {
            var xadapter = (IComponentAdapter) new XComponentAdapter(registry, componentKey, componentImplementation, parameters);
            return isCaching ? new CachingComponentAdapter(xadapter) : xadapter;
        }
    }
}
